package com.telecom.cms.dto;

import java.sql.*;


import com.telecom.cms.dao.GetConnect;
import com.teradata.db.*;
import com.teradata.tap.system.query.QueryException;

/**
 * @author yueying_nishang
 *
 */
public class WebTools {

	public static String getTwoSelectOther(String parName, String parSql) {
		StringBuffer buffer = new StringBuffer("");
		Connection conn = null;
		Statement stm = null;
		ResultSet rs = null;
		try {
			buffer
					.append("<SELECT name='"
							+ parName
							+ "' onChange='ChangeLocation(RoleArray,entityForm.CampName[entityForm.CampName.selectedIndex].value,entityForm.CampSeqName)'>");
			// DBConnection dbConn = new DBConnection();
			try {
				// conn = dbConn.getConnFromDS("java:jdbc/TeradataCMS");
				conn = (new GetConnect()).getConnection();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			stm = conn.createStatement();
			rs = stm.executeQuery(parSql);

			buffer.append("<OPTION VALUE=\"\" SELECTED>--营销活动--</OPTION>\n");
			while (rs.next()) {
				buffer.append("<OPTION VALUE=\"" + rs.getObject(2) + "\">"
						+ rs.getObject(1) + "</OPTION>\n");
			}

			buffer.append("</SELECT>");

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			try {

				rs.close();
				stm.close();
				rs = null;
				stm = null;

			} catch (Exception e) {
			}
		}

		return buffer.toString();
	}

	public static String getTwoSelectOther2(String parName, String parSql) {
		StringBuffer buffer = new StringBuffer("");
		Connection conn = null;
		Statement stm = null;
		ResultSet rs = null;
		try {
			buffer.append("<SELECT name='" + parName + "'   >");
			// DBConnection dbConn = new DBConnection();
			try {
				conn = (new GetConnect()).getConnection();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			stm = conn.createStatement();
			rs = stm.executeQuery(parSql);
			buffer.append("<OPTION VALUE=\"\" SELECTED>--波次选择--</OPTION>\n");

			while (rs.next()) {

				buffer.append("<OPTION VALUE=\"" + rs.getObject(2) + "\">"
						+ rs.getObject(1) + "</OPTION>\n");
			}

			buffer.append("</SELECT>");

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			try {

				rs.close();
				stm.close();
				rs = null;
				stm = null;

			} catch (Exception e) {
			}
		}

		return buffer.toString();
	}

}
